﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProgramMain.Database;

namespace ProgramMain.OpticNet
{
    public partial class CableTunnelDetail : ProgramMain.Framework.BaseModalDetailCtl
    {
        public CableTunnelDetail()
        {
            InitializeComponent();
        }

        protected override void InitializeDataControls()
        {
            this.ownerCompaniesTableAdapter.SelectCommandTimeout =
                ProgramMain.Properties.Settings.Default.LongQueryTimeout;
            this.ownerCompaniesTableAdapter.Fill(this.simpleOpticNetDB.OwnerCompanies, null);

            this.cableTunnelTypesTableAdapter.SelectCommandTimeout =
    ProgramMain.Properties.Settings.Default.LongQueryTimeout;
            this.cableTunnelTypesTableAdapter.Fill(this.simpleOpticNetDB.CableTunnelTypes, null);

            if (ShowMode == ShowModeTypes.Add)
                try
                {
                    SimpleOpticNetDB.CableTunnelsRow row = (SimpleOpticNetDB.CableTunnelsRow)CurrentRowView.Row;
                    if (this.ownerCompaniesBindingSource.Count > 0)
                    {
                        this.ownerCompaniesBindingSource.MoveFirst();
                        for (int i = 0; i < ownerCompaniesBindingSource.Count; i++)
                        {
                            SimpleOpticNetDB.OwnerCompaniesRow ownerCompaniesRow =
                                (SimpleOpticNetDB.OwnerCompaniesRow)
                                ((DataRowView)this.ownerCompaniesBindingSource.Current).Row;
                            if (row != null && ownerCompaniesRow != null && ownerCompaniesRow.IsDefault)
                                row.OwnerCompanyID = ownerCompaniesRow.ID;
                        }

                        this.CableTunnelTypeBindingSource.MoveFirst();
                        for (int i = 0; i < CableTunnelTypeBindingSource.Count; i++)
                        {
                            SimpleOpticNetDB.CableTunnelTypesRow cableTunnelTypesRow =
                                (SimpleOpticNetDB.CableTunnelTypesRow)
                                ((DataRowView)this.ownerCompaniesBindingSource.Current).Row;
                            if (row != null && cableTunnelTypesRow != null && cableTunnelTypesRow.IsDefault)
                                row.CableTunnelTypeID = cableTunnelTypesRow.ID;
                        }
                    }
                    
                }
                catch
                {
                }
        }

        protected override void BindDataControls()
        {
            this.lookupOwnerCompanyID.DataBindings.Add(new Binding("EditValue", this.dataSource, "OwnerCompanyID"));
            this.lookUpCableTunnelTypeID.DataBindings.Add(new Binding("EditValue", this.dataSource, "CableTunnelTypeID"));
            this.txtEditCaption.DataBindings.Add(new Binding("Text", this.dataSource, "Caption"));
            this.txtEditLongitude1.DataBindings.Add(new Binding("Text", this.dataSource, "Longitude1"));
            this.txtEditLatitude1.DataBindings.Add(new Binding("Text", this.dataSource, "Latitude1"));
            this.txtEditLongitude2.DataBindings.Add(new Binding("Text", this.dataSource, "Longitude2"));
            this.txtEditLatitude2.DataBindings.Add(new Binding("Text", this.dataSource, "Latitude2"));
            this.txtEditLength.DataBindings.Add(new Binding("Text", this.dataSource, "Length"));
        }
    }
}
